package com.chc.util;


import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class ServiceLocator {
	private ServiceLocator(ServletContext sc){
		 cx= WebApplicationContextUtils.getWebApplicationContext(sc);
	}
	private static volatile ServiceLocator instanse;
	private WebApplicationContext  cx;
	
	public static ServiceLocator getInstanse(ServletContext sc) {
		if(instanse == null) {
			synchronized (ServiceLocator.class) {
				if(instanse == null) {
					instanse = new ServiceLocator(sc);
				}
			}
		}
		return instanse;
	}
	public Object getBean(String id){
		return cx.getBean(id);
	}
	
}
